<script lang="ts" setup>
import { reactive } from 'vue';

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);

const state = reactive({
  ruleForm: {} as any,
  dialog: {
    isShowDialog: false,
    type: '',
    title: '',
    submitTxt: '',
  },
});

const openDialog = (type: string, row: RowDicType) => {
  if (type === 'edit') {
    state.ruleForm = row;
    state.dialog.title = '修改';
    state.dialog.submitTxt = '修 改';
  } else {
    state.dialog.title = '新增';
    state.dialog.submitTxt = '新 增';
    // 清空表单，此项需加表单验证才能使用
    // nextTick(() => {
    // 	dicDialogFormRef.value.resetFields();
    // });
  }
  state.dialog.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
  state.dialog.isShowDialog = false;
};
// 取消
const onCancel = () => {
  closeDialog();
};
// 提交
const onSubmit = () => {
  closeDialog();
  emit('refresh');
  // if (state.dialog.type === 'add') { }
};

// 暴露变量
defineExpose({
  openDialog,
});
</script>

<template>
  <div class="system-dic-dialog-container">
    <el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="1080px">
      <el-form ref="dicDialogFormRef" :model="state.ruleForm" label-width="110px">
        <el-form-item label="数据名称">
          <el-input v-model="state.ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="预警单元数据">
          <el-radio-group v-model="state.ruleForm.type">
            <el-radio value="1">30 x 30 米</el-radio>
            <el-radio value="2">1000 x 1000 米</el-radio>
            <el-radio value="3">地块单元数据</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="关联融合数据" position="top">
          <!-- <el-select v-model="state.ruleForm.value" placeholder="请选择">
            <el-option label="土壤调查数据" value="1" />
            <el-option label="土壤图" value="2" />
          </el-select>-->
          <el-table data="tableData" border>
            <el-table-column prop="index" label="序号" width="80" />
            <el-table-column prop="name" label="关联数据" width="180" />
            <el-table-column prop="zbmc" label="关联指标字段名称" />
            <el-table-column prop="type" label="指标数据类型" />
            <el-table-column prop="method" label="融合方法" />
            <el-table-column prop="handle" label="操作" fixed="right">
              <template #default="scope">
                <el-button text type="primary">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-button class="mt14" style="width: 100%"> 添加 </el-button>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="onCancel">取 消</el-button>
          <el-button type="primary" @click="onSubmit">融合处理</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<style scoped lang="scss"></style>
